package com.qf.fronted.dao.selectaddress.impl;

import com.qf.fronted.dao.selectaddress.ICityDao;
import com.qf.fronted.domain.City;
import com.qf.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CityDaoImpl implements ICityDao {

    private QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());

    //根据省份id查询城市列表
    @Override
    public List<City> selectCityByProvinceId(Integer provinceId) {
        String sql = "SELECT id,name FROM city WHERE provinceId=?";
        try {
             return queryRunner.query(sql, new BeanListHandler<>(City.class), provinceId);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return new ArrayList<>(0);
    }
}
